package com.example.factory.api.controller;

import com.example.factory.api.dto.DtoAuditDetails;
import com.example.factory.api.dto.DtoReport;
import com.example.factory.api.dto.DtoReporterReport;
import com.example.factory.api.dto.Response;
import com.example.factory.api.dto.form.DtoReportForm;
import com.example.factory.api.facade.ReportFacade;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Lei Tao
 */
@RestController
@RequestMapping("/admin/report")
public class ReportController {

    private final ReportFacade reportFacade;

    public ReportController(ReportFacade reportFacade) {
        this.reportFacade = reportFacade;
    }

    @PostMapping("/save")
    public Response<DtoReport> saveOrUpdate(@RequestBody DtoReportForm dtoReportForm) {
        return reportFacade.saveOrUpdate(dtoReportForm);
    }

    @GetMapping("/list")
    public Response<List<DtoReport>> list() {
        return reportFacade.list();
    }

    @GetMapping("/{reportGuid}/details")
    public Response<DtoReport> details(@PathVariable("reportGuid") String reportGuid) {
        return reportFacade.details(reportGuid);
    }

    @GetMapping("/{reportGuid}/delete")
    public Response<Void> delete(@PathVariable("reportGuid") String reportGuid) {
        return reportFacade.delete(reportGuid);
    }

    @GetMapping("/{reportGuid}/audit")
    public Response<DtoReporterReport> audit(@PathVariable("reportGuid")String reportGuid) {
        return reportFacade.audit(reportGuid);
    }
    @GetMapping("/{reportGuid}/audit/details")
    public Response<List<DtoAuditDetails>> auditDetails(@PathVariable("reportGuid")String reportGuid) {
        return reportFacade.auditDetails(reportGuid);
    }
}
